package com.woniu.smart.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniu.smart.dto.OperationDTO;
import com.woniu.smart.entity.Operation;
import com.woniu.smart.entity.RepairType;
import com.woniu.smart.mapper.OperationMapper;
import com.woniu.smart.mapper.RepairTypeMapper;
import com.woniu.smart.mapper.WarningMapper;
import com.woniu.smart.service.OperationService;
import com.woniu.smart.vo.OperationVO;
import com.woniu.smart.vo.WarningVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @program: smart
 * @description:
 * @author: qqq
 * @create: 2022-10-23 14:32
 **/
@Service
public class OperationServiceImpl implements OperationService {
    @Autowired
    private OperationMapper operationMapper;
    @Autowired
    private RepairTypeMapper repairTypeMapper;
    @Autowired
    private WarningMapper warningMapper;
    @Override
    public List<OperationVO> selectAll(OperationDTO operationDTO) {
        PageHelper.startPage(operationDTO.getCurrentPage(),operationDTO.getPageSize());
        return operationMapper.selectAll(operationDTO);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return operationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Operation record) {
        return operationMapper.insert(record);
    }

    @Override
    public int insertSelective(WarningVO record) {
        return operationMapper.insertSelective(record);
    }

    @Override
    public List<RepairType> selectAll() {
        return repairTypeMapper.selectAll();
    }

    @Override
    public OperationVO selectByPrimaryKey(Long id) {
        return operationMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public int dispose(OperationVO operationVO) {
        operationVO.setOperationStatus(3);
        operationVO.setWarningStatus(3);
        operationVO.setOperationTime(new Date());
        int i = operationMapper.updateByPrimaryKeySelective(operationVO);
        int i2 = warningMapper.updateByOperationPrimaryKey(operationVO);
        return 1;
    }

    @Override
    public int updateByPrimaryKeySelective(OperationVO record) {
        return operationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Operation record) {
        return operationMapper.updateByPrimaryKey(record);
    }
}
